import os.path
import allure
import pytest
from playwright.sync_api import Playwright,Page,expect
from pages.Download_ToDesk_Page import Download_ToDesk_Page


class Test_Download_ToDesk_Page:
    """下载到桌面"""

    @pytest.fixture(autouse=True)
    def before_for_each_function(self,page):
        print('-----start-----')
        self.page = Download_ToDesk_Page(page)
        self.page.navigate()
        yield
        print('-----end-----')

    @allure.title('下载到桌面')
    def test_download_toDesk_page(self):
        with self.page.page.expect_download() as download_info:
            self.page.download_todesk_button.click()

        download_file = download_info.value
        download_file.path = download_file.path()
        path = download_file.suggested_filename
        download_file.save_as(rf'F:\Playwright_Project_POM\download_Files\{path}')
        assert rf'F:\Playwright_Project_POM\download_Files\{path}' is not None
        self.page.page.close()